#include "barrier.h"

void do_barrier_init(barrier_t *barrier, int goal)
{
    barrier->goal_num = goal;
    barrier->cur_num = 0;
    queue_init(&barrier->wait_queue);
}

void do_barrier_wait(barrier_t *barrier)
{
    barrier->cur_num++;
    if (barrier->cur_num < barrier->goal_num)
    {
        do_block(&barrier->wait_queue);
        do_scheduler();
    }
    else
    {
       do_unblock_all(&barrier->wait_queue);
        barrier->cur_num = 0;
    }
}